package com.jpa_demo.service;

import com.jpa_demo.entity.User;
import com.jpa_demo.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    @Transactional
    public int update() {
        return userRepository.updateUser("王五", 1);
    }

    @Transactional
    public int delete(int id) {
        return userRepository.deleteById(id);
    }

    @Transactional
    public void insert(User user){
        userRepository.save(user);
    }
}
